import QRequest from '@/service/index';
import { generateNameToLevel } from '@/config/constant';

import {
    CustomerInformationPageResponse,
    CustomerInformationPageParams,
    CustomerInformationListInfo
} from './model/type';

/**
 * @:获取客户信息列表
 * @param {CustomerInformationPageParams} params
 * @return {*}
 */
export const doGetCustomerInformationList = (
    params: CustomerInformationPageParams,
    level?: string
) => {
    return QRequest.get<CustomerInformationPageResponse>(`/customerInformation/selectAll`, {
        params,
        headers:
            level == null
                ? {}
                : {
                      loadingTarget: `#${generateNameToLevel(level)}`
                  }
    });
};

/**
 * @: 删除客户信息
 * @param {number[]} params
 * @return {*}
 */
export const doDelCustomerInformation = (data: number[]) => {
    return QRequest.delete(`/customerInformation/delete`, {
        data,
        headers: {
            hideLoading: 1
        }
    });
};

/**
 * @: 新增客户信息
 * @param {CustomerInformationEditRequest} data
 * @return {*}
 */
export const doAddCustomerInformation = (data: CustomerInformationListInfo[]) => {
    return QRequest.post(`/customerInformation/save`, data, {
        headers: {
            hideLoading: 1
        }
    });
};

/**
 * @: 编辑客户信息
 * @param {CustomerInformationEditRequest} data
 * @return {*}
 */
export const doUpdateCustomerInformation = (data: CustomerInformationListInfo) => {
    return QRequest.put(`/customerInformation/update`, data, {
        headers: {
            hideLoading: 1
        }
    });
};
